package main

import (
	"context"
	"encoding/json"
	"github.com/zing-dev/general-protocol-lib/log"
	"github.com/zing-dev/general-protocol-lib/source/dfvs"
)

func main() {
	log.Init()
	config := dfvs.NewConfig()
	config.SetDebug(true)
	app := dfvs.NewApp(context.Background(), config)
	devices := []*dfvs.SensorChannel{{SensorId: "860965064245288", ChannelId: 1}}
	for _, device := range devices {
		app.Channel.Store(device.SensorId, device)
	}
	err := app.Run()
	if err != nil {
		log.L.Fatalln(err)
	}
	for {
		select {
		case err := <-app.Message:
			log.L.Error(err)
		case status := <-app.FiberStatus:
			data, _ := json.Marshal(status)
			log.L.Info(string(data))
		case signal := <-app.FiberSignal:
			log.L.Println(signal)
		case alarms := <-app.FiberAlarm:
			log.L.Println(alarms)
		case hb := <-app.Heartbeat:
			log.L.Info(hb)

		}
	}
}
